import * as THREE from 'three'

// 创建地面
const groundGeometry = new THREE.PlaneGeometry(500, 500)
const groundMaterial = new THREE.MeshLambertMaterial({
  color: 0xffffff,
  side: THREE.DoubleSide, // 双面着色
})
const ground = new THREE.Mesh(groundGeometry, groundMaterial)
ground.rotation.x = -Math.PI / 2
ground.receiveShadow = true

// 随机函数
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min
}
// 创建立方体

let cubes = []
const createBox = () => {
  for (let i = 0,len = 200; i < len; i++) {
    const width = getRandomInt(4,9)
    const height = getRandomInt(2,10)
    const depth = getRandomInt(3,8)
    const cubeGeometry = new THREE.BoxGeometry(width, height, depth)
    const cubeMaterial = new THREE.MeshLambertMaterial({
      color: 0xff0000,
    })
    const cube = new THREE.Mesh(cubeGeometry, cubeMaterial)
    cube.position.x = getRandomInt(-250, 250)
    cube.position.z = getRandomInt(-250, -10)
    cube.position.y = height / 2
    cube.castShadow = true
    cubes.push(cube)
  }
}
createBox() // 创建立方体

export {
  ground, // 导出地面
  cubes
}